package com.alan.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * 接收消息的线程
 * Created by Alan on 2017/8/5.
 */
public class Receive extends Thread {

    private Socket socket;

    public Receive(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            //得到输入流
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            while (true){
                String info = br.readLine();
                System.out.println(info);
                if(info.endsWith("bye")){
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}


